<template>
  <div class="container">
    <div class="login-image">
      <div class="image"></div>
    </div>
    <div :class="{ login: true, active: isLogin }">
      <div class="title">登录</div>
      <el-form
        ref="ruleFormRef"
        style="max-width: 400px"
        :model="ruleForm"
        status-icon
        :rules="rules"
        label-width="auto"
        class="login-form"
      >
        <el-form-item label="用户名" prop="username">
          <el-input v-model="ruleForm.username" />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input
            v-model="ruleForm.password"
            type="password"
            autocomplete="off"
          />
        </el-form-item>
        <el-form-item class="button-form-item">
          <el-button type="primary" @click="submitForm(ruleFormRef)">
            登录
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import type { FormInstance, FormRules } from 'element-plus'
import {useStore} from "vuex";
import {useRouter} from "vue-router";

const store = useStore()
const router = useRouter()
const ruleFormRef = ref<FormInstance>()
const isLogin = ref<boolean>(false)
const ruleForm = ref({
  username: '',
  password: '',
})

const rules = ref<FormRules<typeof ruleForm>>({
  username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
  password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
})

const submitForm = (formEl: FormInstance | undefined) => {
  isLogin.value = true
  if (!formEl) return
  formEl.validate((valid) => {
    if (valid) {
      store.dispatch("auth/setIsLogin",true)
      router.push("/")
      console.log('submit!')
    } else {
      console.log('error submit!')
    }
  })
}
</script>

<style scoped lang="scss">
.container {
  box-sizing: border-box;
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  background-color: #edf9fb;
  position: relative;
  padding: 0 100px;
  .login {
    position: relative;
    width: 25%;
    height: 40%;
    background-color: #ffffff;
    border-radius: 10px;
    padding: 0 24px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    .login-form {
      z-index: 1;
    }
    &:hover:before {
      transform: translateX(200%);
      transition: all 0.5s ease-in-out;
    }
    &:hover:after {
      transform: translateX(-200%);
      transition: all 0.5s ease-in-out;
    }
    &:before {
      content: '';
      top: -25%;
      left: -25%;
      width: 50%;
      height: 50%;
      position: absolute;
      background-color: #1bc972;
      border-radius: 37% 63% 68% 32% / 54% 64% 36% 46%;
      z-index: 0;
      transform: translateX(0) scale(1);
      transition: all 0.5s ease-in-out;
    }
    &:after {
      content: '';
      bottom: -25%;
      right: -25%;
      width: 50%;
      height: 50%;
      position: absolute;
      background-color: #1bc972;
      border-radius: 37% 63% 68% 32% / 54% 64% 36% 46%;
      z-index: 0;
      transform: translateX(0);
      transition: all 0.5s ease-in-out;
    }
    .title {
      user-select: none;
      font-size: 48px;
      padding: 24px 0;
      color: transparent;
      -webkit-text-stroke-width: 1px;
      -moz-text-stroke-width: 1px;
      -webkit-text-stroke-color: #dd9500;
      -moz-text-stroke-color: #dd9500;
      text-shadow: 6px 6px 3px #00dd95;
      z-index: 1;
    }
    .button-form-item {
      ::v-deep(.el-form-item__content) {
        justify-content: flex-end !important;
      }
    }
  }
  .active {
    &:hover:before {
      transform: translate(150%) scale(4);
      transition: all 0.5s ease-in-out;
    }
    &:hover:after {
      transform: translate(-150%) scale(4);
      transition: all 0.5s ease-in-out;
    }
  }
  &:before {
    content: '';
    position: absolute;
    top: 25%;
    left: 10%;
    width: 500px;
    height: 500px;
    background-image: url('@/assets/images/login-image.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
  }
}
</style>
